// pages/douban/douban.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inTheaters :{},
    comingSoon: {},
    Top250: {},
    hidden:true,
    hiddenLoading: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading({
      title: '加载中...',
    })
    // 获取正在上映的电影数据
    var inTheaters = app.url + '/v2/movie/in_theaters' + "?start=0&count=6";
    this.request(inTheaters, "inTheaters","正在上映")
    // 获取即将上映的电影数据
    var comingSoon = app.url + "/v2/movie/coming_soon" + "?start=0&count=6";
    this.request(comingSoon, "comingSoon","即将上映")
    // 获取热门电影数据
    var Top250 = app.url + "/v2/movie/top250" + "?start=0&count=6";
    this.request(Top250, "Top250","热门电影")
  },
  // 获取数据
  request: function (url,count,top){
    var that = this;
    console.log(url)
    wx.request({
      url: url,
      success: function (e) {
        console.log(e)
        that.shuju(e.data, count, top)
        that.setData({
          hiddenLoading: true
        })
      }
    })
  },
  shuju: function (e, count, top){
    var title = count + ".title";
    var content = count + ".content";
    var shujus = e.subjects;
    for(var i = 0;i < shujus.length;i++){
      shujus[i].rating.stars = shujus[i].rating.stars.substr(0,1);
      shujus[i].num = 5;
    }

    this.setData({
      [content]: shujus,
      [title]: top,
    })
  },
  Goss:function(){
    wx.navigateTo({
      url:"/pages/douban/douban-ss/douban-ss"
    })
  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    wx.hideLoading()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },


  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

})